const address = require("../service/address");
const ApiResult = require("../common/ApiResult");
const Enum = require("../enum");

module.exports = {
  setByIp: async function(ctx) {
    const userAddress = ctx.request.body;
    if (!Object.keys(userAddress).length) {
      ctx.body = ApiResult.ERROR(Enum.PARAM_ERROR);
      return;
    }
    try {
      await address.insertOrUpdate(userAddress);
      ctx.response.type = "json";
      ctx.body = ApiResult.SUCCESS();
    } catch (e) {
      ctx.body = ApiResult.ERROR(e.message);
    }
  }
};
